/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package helpdesk;


import java.io.*;
import java.sql.*;
import javax.swing.*;
import java.net.MalformedURLException;
import java.net.SocketException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.filechooser.FileFilter;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;
import org.apache.commons.net.ftp.FTPFile;


public class StudentForm extends javax.swing.JFrame {

    String AnnouncementText[] = new String[1000];
    String AnnouncementAuthor[] = new String[1000];
    int AnnouncementUID[] = new int[1000];
    String FormFilePath[] = new String[1000];
    String FormAuthor[] = new String[1000];
    int FormUID[] = new int[1000];
    int FormReviewed[] = new int[1000];
    String QuestionText[] = new String[1000];
    String QuestionAuthor[] = new String[1000];
    String QuestionReplyText[] = new String[1000];
    String QuestionReplyAuthor[] = new String[1000];
    int QuestionGlobal[] = new int[1000];
    int QuestionCategory[] = new int[100];
    int QuestionUID[] = new int[1000];
    String UserUsername[] = new String[1000];
    String UserFirst[] = new String[1000];
    String UserLast[] = new String[1000];
    int UserAccountType[] = new int[1000];
    int intQuestionSort = 0;
    int intGradAsstCount = 0;
    int intStudentCount = 0;
    String strStudentUsername[] = new String[1000];
    String strGradAsstUsernames[] = new String[1000];
    File submitForm = null;
    double lastClick = 0;
    double doubleClickSensitivity = 500; // ms
    int clicks = 0;
    int schedIndex = 0;
    
    // Creates new form StudentMainForm
    public StudentForm() {
        initComponents();
    }
        
    public void updateForm()
    {
        // string to store username
        String strUsername = HelpDesk.accountName;
            
        // depending on acount type set the correct panel visibility
        switch(HelpDesk.accountType){
            case 0: // student account
                panViewQs.setVisible(true);
                lblSortByVis.setVisible(false);
                cmbSortByVis.setVisible(false);
                panPostQ.setVisible(true);
                panViewForms.setVisible(true);
                btnReviewed.setVisible(false);
                panSubmitForm.setVisible(true);
                panSetSchedule.setVisible(false);
                panViewSchedules.setVisible(false);
                panEditRoles.setVisible(false);
                panPostAnnc.setVisible(false);
                break;
            case 1: // graduate assistant account
                panViewQs.setVisible(true);
                lblSortByVis.setVisible(true);
                cmbSortByVis.setVisible(true);
                panPostQ.setVisible(false);
                panViewForms.setVisible(true);
                btnReviewed.setVisible(true);
                panSubmitForm.setVisible(false);
                panSetSchedule.setVisible(true);
                panViewSchedules.setVisible(false);
                panEditRoles.setVisible(false);
                panPostAnnc.setVisible(true);
                break;
            case 2: // graduate office coordinator
                panViewQs.setVisible(true);
                lblSortByVis.setVisible(true);
                cmbSortByVis.setVisible(true);
                panPostQ.setVisible(false);
                panViewForms.setVisible(true);
                btnReviewed.setVisible(true);
                panSubmitForm.setVisible(false);
                panSetSchedule.setVisible(false);
                panViewSchedules.setVisible(true);
                panEditRoles.setVisible(true);
                panPostAnnc.setVisible(true);
                break;
            default: // not valid account
                //do nothing
                break;
        }
        
        try
        {
            Statement sS = HelpDesk.connection.createStatement ();
            String myQueryS = "SELECT UID, text, author FROM tblAnnouncements";
            sS.executeQuery(myQueryS);
            ResultSet rsS = sS.getResultSet ();
            int count = 0;
            while (rsS.next ())
            {
                AnnouncementText[count] = rsS.getString ("text");
                AnnouncementAuthor[count] = rsS.getString ("author");
                AnnouncementUID[count] = rsS.getInt("UID");
                tblAnnouncements.setValueAt(AnnouncementAuthor[count], count, 0);
                tblAnnouncements.setValueAt(AnnouncementText[count], count, 1);                
                ++count;
            }
            rsS.close ();
            sS.close ();
            
            
            // if user is a student
            if(HelpDesk.accountType == 0)
            {
                Statement sT = HelpDesk.connection.createStatement ();
                String myQueryT = "SELECT UID, text, author, replyText, replyAuthor, global, category FROM tblQuestions WHERE (global=1) OR (author='"+ strUsername +"')";
                sT.executeQuery(myQueryT);
                ResultSet rsT = sT.getResultSet ();
                count = 0;
                while (rsT.next ())
                {
                    QuestionText[count] = rsT.getString ("text");
                    QuestionAuthor[count] = rsT.getString ("author");
                    QuestionUID[count] = rsT.getInt("UID");
                    QuestionReplyText[count] = rsT.getString ("replyText");
                    QuestionReplyAuthor[count] = rsT.getString ("replyAuthor");
                    QuestionGlobal[count] = rsT.getInt ("global");
                    QuestionCategory[count] = rsT.getInt ("category");
                    tblQuestions.setValueAt(QuestionAuthor[count],count,0);
                    tblQuestions.setValueAt(QuestionText[count],count,1);
                    if(QuestionCategory[count] == 0)
                    {
                        tblQuestions.setValueAt("General",count,2);
                    }
                    else if(QuestionCategory[count] == 1)
                    {
                        tblQuestions.setValueAt("Scheduling",count,2);
                    }
                    else if(QuestionCategory[count] == 2)
                    {
                        tblQuestions.setValueAt("Financial",count,2);
                    }
                    else
                    {
                        //do nothing
                    }
                    tblQuestions.setValueAt(QuestionReplyAuthor[count],count,3);
                    tblQuestions.setValueAt(QuestionReplyText[count],count,4);
                    ++count;
                }
                rsT.close ();
                sT.close ();
                
                
                // display forms for students
                Statement sU = HelpDesk.connection.createStatement ();
                String myQueryU = "SELECT UID, filePath, author, reviewed FROM tblForms WHERE (author='"+ strUsername +"')";
                sU.executeQuery(myQueryU);
                ResultSet rsU = sU.getResultSet ();
                count = 0;
                while (rsU.next ())
                {
                    FormFilePath[count] = rsU.getString ("filePath");
                    FormAuthor[count] = rsU.getString ("author");
                    FormReviewed[count] = rsU.getInt("reviewed");
                    tblForm.setValueAt(FormAuthor[count],count,0);
                    tblForm.setValueAt(FormFilePath[count],count,1);
                    if(FormReviewed[count] == 0)
                    {
                    tblForm.setValueAt("Not Reviewed",count,2); 
                    }
                    else if(FormReviewed[count] == 1)
                    {
                        tblForm.setValueAt("Reviewed",count,2);
                    }
                    else
                    {
                        //do nothing
                    }
                    ++count;
                } 
                rsU.close ();
                sU.close ();
            }
            else // account is grad asst or grad office coord
            {
                
                // display questions
                switch(intQuestionSort){
                    case 0:
                        Statement sT0 = HelpDesk.connection.createStatement ();
                        String myQueryT0 = "SELECT UID, text, author, replyText, replyAuthor, global, category FROM tblQuestions WHERE (global=1) OR (author='"+ strUsername +"')";
                        sT0.executeQuery(myQueryT0);
                        ResultSet rsT0 = sT0.getResultSet ();
                        count = 0;
                        while (rsT0.next ())
                        {
                            QuestionText[count] = rsT0.getString ("text");
                            QuestionAuthor[count] = rsT0.getString ("author");
                            QuestionUID[count] = rsT0.getInt("UID");
                            QuestionReplyText[count] = rsT0.getString ("replyText");
                            QuestionReplyAuthor[count] = rsT0.getString ("replyAuthor");
                            QuestionGlobal[count] = rsT0.getInt ("global");
                            QuestionCategory[count] = rsT0.getInt ("category");
                            tblQuestions.setValueAt(QuestionAuthor[count],count,0);
                            tblQuestions.setValueAt(QuestionText[count],count,1);
                            if(QuestionCategory[count] == 0)
                            {
                                tblQuestions.setValueAt("General",count,2);
                            }
                            else if(QuestionCategory[count] == 1)
                            {
                                tblQuestions.setValueAt("Scheduling",count,2);
                            }
                            else if(QuestionCategory[count] == 2)
                            {
                                tblQuestions.setValueAt("Financial",count,2);
                            }
                            else
                            {
                                //do nothing
                            }
                            tblQuestions.setValueAt(QuestionReplyAuthor[count],count,3);
                            tblQuestions.setValueAt(QuestionReplyText[count],count,4);
                            ++count;
                        }
                        rsT0.close ();
                        sT0.close ();
                        break;
                    case 1: case 2:
                        Statement sT1 = HelpDesk.connection.createStatement ();
                        String myQueryT1 = "SELECT UID, text, author, replyText, replyAuthor, global, category FROM tblQuestions WHERE (global=1) OR (author='"+ strUsername +"')";
                        sT1.executeQuery(myQueryT1);
                        ResultSet rsT1 = sT1.getResultSet ();
                        count = 0;
                        while (rsT1.next ())
                        {
                            QuestionText[count] = rsT1.getString ("text");
                            QuestionAuthor[count] = rsT1.getString ("author");
                            QuestionUID[count] = rsT1.getInt("UID");
                            QuestionReplyText[count] = rsT1.getString ("replyText");
                            QuestionReplyAuthor[count] = rsT1.getString ("replyAuthor");
                            QuestionGlobal[count] = rsT1.getInt ("global");
                            QuestionCategory[count] = rsT1.getInt ("category");
                            tblQuestions.setValueAt(QuestionAuthor[count],count,0);
                            tblQuestions.setValueAt(QuestionText[count],count,1);
                            if(QuestionCategory[count] == 0)
                            {
                                tblQuestions.setValueAt("General",count,2);
                            }
                            else if(QuestionCategory[count] == 1)
                            {
                                tblQuestions.setValueAt("Scheduling",count,2);
                            }
                            else if(QuestionCategory[count] == 2)
                            {
                                tblQuestions.setValueAt("Financial",count,2);
                            }
                            else
                            {
                                //do nothing
                            }
                            tblQuestions.setValueAt(QuestionReplyAuthor[count],count,3);
                            tblQuestions.setValueAt(QuestionReplyText[count],count,4);
                            ++count;
                        }
                        rsT1.close ();
                        sT1.close ();
                        break;
                    default:
                        //do nothing
                        break;
                }
                
                // display forms for grads
                Statement sU = HelpDesk.connection.createStatement ();
                String myQueryU = "SELECT UID, filePath, author, reviewed FROM tblForms";
                sU.executeQuery(myQueryU);
                ResultSet rsU = sU.getResultSet ();
                count = 0;
                while (rsU.next ())
                {
                    FormFilePath[count] = rsU.getString ("filePath");
                    FormAuthor[count] = rsU.getString ("author");
                    FormReviewed[count] = rsU.getInt("reviewed");
                    tblForm.setValueAt(FormAuthor[count],count,0);
                    tblForm.setValueAt(FormFilePath[count],count,1);
                    if(FormReviewed[count] == 0)
                    {
                    tblForm.setValueAt("Not Reviewed",count,2); 
                    }
                    else if(FormReviewed[count] == 1)
                    {
                        tblForm.setValueAt("Reviewed",count,2);
                    }
                    else
                    {
                        //do nothing
                    }
                    ++count;
                } 

                rsU.close ();
                sU.close ();
            }

            cmbGradAsst.removeAllItems();
            cmbGradAsst.addItem("----------");
            
            Statement sV = HelpDesk.connection.createStatement ();
            String myQueryV = "SELECT username, firstName, lastName, accountType FROM tblUsers";
            sV.executeQuery(myQueryV);
            ResultSet rsV = sV.getResultSet ();
            count = 0;
            intStudentCount = 0;
            intGradAsstCount = 0;
            while (rsV.next ())
            {
                UserUsername[count] = rsV.getString ("username");
                UserFirst[count] = rsV.getString ("firstName");
                UserLast[count] = rsV.getString("lastName");
                UserAccountType[count] = rsV.getInt("accountType");
                if(UserAccountType[count] == 0)
                {
                    tblStudents.setValueAt(UserFirst[count], intStudentCount, 0);
                    tblStudents.setValueAt(UserLast[count], intStudentCount, 1);
                    tblStudents.setValueAt(UserUsername[count], intStudentCount, 2);
                    intStudentCount++;
                }
                else if(UserAccountType[count] == 1)
                {
                    tblGradAssts.setValueAt(UserFirst[count], intGradAsstCount, 0);
                    tblGradAssts.setValueAt(UserLast[count], intGradAsstCount, 1);
                    tblGradAssts.setValueAt(UserUsername[count], intGradAsstCount, 2);
                    String strFullName = (UserFirst[count] + " " + UserLast[count]);
                    cmbGradAsst.addItem(strFullName);
                    strGradAsstUsernames[intGradAsstCount] = UserUsername[count];
                    intGradAsstCount++;
                }
                else 
                {
                    //do nothing
                }
                ++count;
            }
            rsV.close ();
            sV.close ();
            
        }
        catch (SQLException error)
        {
            System.err.println ("Error message: " + error.getMessage ());
            System.err.println ("Error number: " + error.getErrorCode ());
        }

       
        // set all boolean values to false in set availability schedule table
        for(int y = 0; y < 9; y++) 
        {
            for (int z = 1; z < 6; z++) {
                tblAvail.setValueAt(false, y, z);
            }
        }
        
        // set all boolean values to false in view availability schedule table
        for(int yy = 0; yy < 9; yy++) 
        {
            for (int zz = 1; zz < 6; zz++) {
                tblViewAvail.setValueAt(false, yy, zz);
            }
        }
    
    
        
    }
    


    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panViewAnnc = new javax.swing.JPanel();
        lblViewAnnc = new javax.swing.JLabel();
        btnAnncReply = new javax.swing.JButton();
        jScrollPane5 = new javax.swing.JScrollPane();
        tblAnnouncements = new javax.swing.JTable();
        panPostQ = new javax.swing.JPanel();
        btnPostSubmit = new javax.swing.JButton();
        lblPostQ = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        txtNewQ = new javax.swing.JTextArea();
        cmbCategory = new javax.swing.JComboBox();
        lblCategory = new javax.swing.JLabel();
        cmbVisibility = new javax.swing.JComboBox();
        lblVisibility = new javax.swing.JLabel();
        panSubmitForm = new javax.swing.JPanel();
        btnSubmitForm = new javax.swing.JButton();
        btnBrowse = new javax.swing.JButton();
        txtForm = new javax.swing.JTextField();
        lblSubmitForm = new javax.swing.JLabel();
        panViewForms = new javax.swing.JPanel();
        lblViewForms = new javax.swing.JLabel();
        jScrollPane7 = new javax.swing.JScrollPane();
        tblForm = new javax.swing.JTable();
        btnReviewed = new javax.swing.JButton();
        btnDownloadForm = new javax.swing.JButton();
        btnDeleteForm = new javax.swing.JButton();
        panViewQs = new javax.swing.JPanel();
        lblViewQs = new javax.swing.JLabel();
        btnQReply = new javax.swing.JButton();
        jScrollPane6 = new javax.swing.JScrollPane();
        tblQuestions = new javax.swing.JTable();
        lblSortByVis = new javax.swing.JLabel();
        cmbSortByVis = new javax.swing.JComboBox();
        panSetSchedule = new javax.swing.JPanel();
        jSeparator9 = new javax.swing.JSeparator();
        lblSetSched = new javax.swing.JLabel();
        btnSubmitSchedule = new javax.swing.JButton();
        jScrollPane8 = new javax.swing.JScrollPane();
        tblAvail = new javax.swing.JTable();
        btnReset = new javax.swing.JButton();
        panPostAnnc = new javax.swing.JPanel();
        lblPostAnnc = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        txtAnnc = new javax.swing.JTextArea();
        btnPostAnnc = new javax.swing.JButton();
        panViewSchedules = new javax.swing.JPanel();
        lblViewSched = new javax.swing.JLabel();
        lblGradAsst = new javax.swing.JLabel();
        cmbGradAsst = new javax.swing.JComboBox();
        jScrollPane9 = new javax.swing.JScrollPane();
        tblViewAvail = new javax.swing.JTable();
        btnGoSched = new javax.swing.JButton();
        panEditRoles = new javax.swing.JPanel();
        lblEditRoles = new javax.swing.JLabel();
        lblStudents = new javax.swing.JLabel();
        lblGradAssts = new javax.swing.JLabel();
        btnMakeGradAsst = new javax.swing.JButton();
        btnMakeStudent = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblStudents = new javax.swing.JTable();
        jScrollPane11 = new javax.swing.JScrollPane();
        tblGradAssts = new javax.swing.JTable();
        jMenuBar1 = new javax.swing.JMenuBar();
        menuFile = new javax.swing.JMenu();
        menuLogout = new javax.swing.JMenuItem();
        menuQuit = new javax.swing.JMenuItem();
        menuHelp = new javax.swing.JMenu();
        menuAbout = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        panViewAnnc.setBackground(new java.awt.Color(102, 102, 102));

        lblViewAnnc.setText("View Announcements");

        btnAnncReply.setText("Reply");

        tblAnnouncements.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "Author", "Text"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane5.setViewportView(tblAnnouncements);

        org.jdesktop.layout.GroupLayout panViewAnncLayout = new org.jdesktop.layout.GroupLayout(panViewAnnc);
        panViewAnnc.setLayout(panViewAnncLayout);
        panViewAnncLayout.setHorizontalGroup(
            panViewAnncLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(panViewAnncLayout.createSequentialGroup()
                .addContainerGap()
                .add(panViewAnncLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jScrollPane5, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 668, Short.MAX_VALUE)
                    .add(panViewAnncLayout.createSequentialGroup()
                        .add(panViewAnncLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(btnAnncReply)
                            .add(panViewAnncLayout.createSequentialGroup()
                                .add(lblViewAnnc)
                                .add(225, 225, 225)))
                        .add(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        panViewAnncLayout.setVerticalGroup(
            panViewAnncLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(panViewAnncLayout.createSequentialGroup()
                .add(lblViewAnnc)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(jScrollPane5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 113, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(319, 319, 319)
                .add(btnAnncReply))
        );

        getContentPane().add(panViewAnnc, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, 680, 140));

        panPostQ.setBackground(new java.awt.Color(102, 102, 102));

        btnPostSubmit.setText("Submit");
        btnPostSubmit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPostSubmitActionPerformed(evt);
            }
        });

        lblPostQ.setText("Post New Question");

        txtNewQ.setColumns(20);
        txtNewQ.setRows(5);
        jScrollPane2.setViewportView(txtNewQ);

        cmbCategory.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "General", "Scheduling", "Financial" }));

        lblCategory.setText("Category:");

        cmbVisibility.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Private", "Public" }));

        lblVisibility.setText("Visibility:");

        org.jdesktop.layout.GroupLayout panPostQLayout = new org.jdesktop.layout.GroupLayout(panPostQ);
        panPostQ.setLayout(panPostQLayout);
        panPostQLayout.setHorizontalGroup(
            panPostQLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(panPostQLayout.createSequentialGroup()
                .addContainerGap()
                .add(panPostQLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(lblPostQ)
                    .add(panPostQLayout.createSequentialGroup()
                        .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 397, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(panPostQLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(panPostQLayout.createSequentialGroup()
                                .add(86, 86, 86)
                                .add(btnPostSubmit))
                            .add(panPostQLayout.createSequentialGroup()
                                .add(35, 35, 35)
                                .add(panPostQLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(panPostQLayout.createSequentialGroup()
                                        .add(lblVisibility)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(cmbVisibility, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 148, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                    .add(panPostQLayout.createSequentialGroup()
                                        .add(lblCategory)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(cmbCategory, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 148, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))))))
                .addContainerGap(28, Short.MAX_VALUE))
        );
        panPostQLayout.setVerticalGroup(
            panPostQLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(panPostQLayout.createSequentialGroup()
                .add(panPostQLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(panPostQLayout.createSequentialGroup()
                        .addContainerGap()
                        .add(lblPostQ)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(panPostQLayout.createSequentialGroup()
                        .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .add(panPostQLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(lblVisibility)
                            .add(cmbVisibility, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(panPostQLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(lblCategory)
                            .add(cmbCategory, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(btnPostSubmit, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 29, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(18, Short.MAX_VALUE))
        );

        getContentPane().add(panPostQ, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 520, 680, 130));

        panSubmitForm.setBackground(new java.awt.Color(102, 102, 102));

        btnSubmitForm.setText("Submit");
        btnSubmitForm.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSubmitFormActionPerformed(evt);
            }
        });

        btnBrowse.setText("Browse...");
        btnBrowse.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBrowseActionPerformed(evt);
            }
        });

        lblSubmitForm.setText("Submit New Form");

        org.jdesktop.layout.GroupLayout panSubmitFormLayout = new org.jdesktop.layout.GroupLayout(panSubmitForm);
        panSubmitForm.setLayout(panSubmitFormLayout);
        panSubmitFormLayout.setHorizontalGroup(
            panSubmitFormLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(panSubmitFormLayout.createSequentialGroup()
                .addContainerGap()
                .add(panSubmitFormLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(panSubmitFormLayout.createSequentialGroup()
                        .add(btnBrowse)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(txtForm, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 159, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(btnSubmitForm))
                    .add(lblSubmitForm))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        panSubmitFormLayout.setVerticalGroup(
            panSubmitFormLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(panSubmitFormLayout.createSequentialGroup()
                .addContainerGap()
                .add(lblSubmitForm)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(panSubmitFormLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(txtForm, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(btnBrowse)
                    .add(btnSubmitForm))
                .addContainerGap(22, Short.MAX_VALUE))
        );

        getContentPane().add(panSubmitForm, new org.netbeans.lib.awtextra.AbsoluteConstraints(700, 10, 370, 80));

        panViewForms.setBackground(new java.awt.Color(102, 102, 102));

        lblViewForms.setText("View Submitted Forms");

        tblForm.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "Author", "File Path", "Status"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane7.setViewportView(tblForm);

        btnReviewed.setText("Mark/Unmark As Reviewed");
        btnReviewed.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnReviewedActionPerformed(evt);
            }
        });

        btnDownloadForm.setText("Download Form");
        btnDownloadForm.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDownloadFormActionPerformed(evt);
            }
        });

        btnDeleteForm.setText("Delete Form");
        btnDeleteForm.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeleteFormActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout panViewFormsLayout = new org.jdesktop.layout.GroupLayout(panViewForms);
        panViewForms.setLayout(panViewFormsLayout);
        panViewFormsLayout.setHorizontalGroup(
            panViewFormsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(panViewFormsLayout.createSequentialGroup()
                .addContainerGap()
                .add(panViewFormsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(panViewFormsLayout.createSequentialGroup()
                        .add(lblViewForms)
                        .add(0, 0, Short.MAX_VALUE))
                    .add(jScrollPane7, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 660, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, panViewFormsLayout.createSequentialGroup()
                        .add(btnDownloadForm)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 48, Short.MAX_VALUE)
                        .add(btnDeleteForm)
                        .add(144, 144, 144)
                        .add(btnReviewed)))
                .addContainerGap())
        );
        panViewFormsLayout.setVerticalGroup(
            panViewFormsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(panViewFormsLayout.createSequentialGroup()
                .addContainerGap()
                .add(lblViewForms)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane7, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 101, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(panViewFormsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(btnReviewed)
                    .add(btnDownloadForm)
                    .add(btnDeleteForm))
                .addContainerGap(16, Short.MAX_VALUE))
        );

        getContentPane().add(panViewForms, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 330, 680, 180));

        panViewQs.setBackground(new java.awt.Color(102, 102, 102));

        lblViewQs.setText("View Questions");

        btnQReply.setText("Reply");
        btnQReply.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnQReplyActionPerformed(evt);
            }
        });

        tblQuestions.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Author", "Text", "Category", "Reply Author", "Reply Text"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane6.setViewportView(tblQuestions);

        lblSortByVis.setText("Sort by visibility:");

        cmbSortByVis.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "All (Public & Private)", "Public Questions", "Private Questions" }));
        cmbSortByVis.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbSortByVisActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout panViewQsLayout = new org.jdesktop.layout.GroupLayout(panViewQs);
        panViewQs.setLayout(panViewQsLayout);
        panViewQsLayout.setHorizontalGroup(
            panViewQsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(panViewQsLayout.createSequentialGroup()
                .addContainerGap()
                .add(panViewQsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(panViewQsLayout.createSequentialGroup()
                        .add(lblViewQs)
                        .addContainerGap(577, Short.MAX_VALUE))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, panViewQsLayout.createSequentialGroup()
                        .add(lblSortByVis)
                        .add(18, 18, 18)
                        .add(cmbSortByVis, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 359, Short.MAX_VALUE)
                        .add(btnQReply)
                        .add(34, 34, 34))))
            .add(panViewQsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(panViewQsLayout.createSequentialGroup()
                    .addContainerGap()
                    .add(jScrollPane6, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 668, Short.MAX_VALUE)
                    .addContainerGap()))
        );
        panViewQsLayout.setVerticalGroup(
            panViewQsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(panViewQsLayout.createSequentialGroup()
                .add(lblViewQs)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 105, Short.MAX_VALUE)
                .add(panViewQsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(btnQReply)
                    .add(lblSortByVis)
                    .add(cmbSortByVis, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
            .add(panViewQsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(panViewQsLayout.createSequentialGroup()
                    .add(18, 18, 18)
                    .add(jScrollPane6, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 101, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(31, Short.MAX_VALUE)))
        );

        getContentPane().add(panViewQs, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 170, 680, 150));

        panSetSchedule.setBackground(new java.awt.Color(102, 102, 102));
        panSetSchedule.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
        panSetSchedule.add(jSeparator9, new org.netbeans.lib.awtextra.AbsoluteConstraints(290, 30, -1, 190));

        lblSetSched.setText("Set Availability Schedule");
        panSetSchedule.add(lblSetSched, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 10, -1, -1));

        btnSubmitSchedule.setText("Submit");
        btnSubmitSchedule.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSubmitScheduleActionPerformed(evt);
            }
        });
        panSetSchedule.add(btnSubmitSchedule, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 230, -1, -1));

        tblAvail.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"08:00 AM", null, null, null, null, null},
                {"09:00 AM", null, null, null, null, null},
                {"10:00 AM", null, null, null, null, null},
                {"11:00 AM", null, null, null, null, null},
                {"12:00 PM", null, null, null, null, null},
                {"01:00 PM", null, null, null, null, null},
                {"02:00 PM", null, null, null, null, null},
                {"03:00 PM", null, null, null, null, null},
                {"04:00 PM", null, null, null, null, null}
            },
            new String [] {
                "", "M", "Tu", "W", "Th", "F"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.Boolean.class, java.lang.Boolean.class, java.lang.Boolean.class, java.lang.Boolean.class, java.lang.Boolean.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane8.setViewportView(tblAvail);

        panSetSchedule.add(jScrollPane8, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 50, 240, 170));

        btnReset.setText("Reset");
        btnReset.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnResetActionPerformed(evt);
            }
        });
        panSetSchedule.add(btnReset, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 230, -1, -1));

        getContentPane().add(panSetSchedule, new org.netbeans.lib.awtextra.AbsoluteConstraints(710, 10, 260, -1));

        panPostAnnc.setBackground(new java.awt.Color(102, 102, 102));

        lblPostAnnc.setText("Post Announcement");

        txtAnnc.setColumns(20);
        txtAnnc.setRows(5);
        jScrollPane3.setViewportView(txtAnnc);

        btnPostAnnc.setText("Submit");
        btnPostAnnc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPostAnncActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout panPostAnncLayout = new org.jdesktop.layout.GroupLayout(panPostAnnc);
        panPostAnnc.setLayout(panPostAnncLayout);
        panPostAnncLayout.setHorizontalGroup(
            panPostAnncLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(panPostAnncLayout.createSequentialGroup()
                .addContainerGap()
                .add(panPostAnncLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(panPostAnncLayout.createSequentialGroup()
                        .add(lblPostAnnc)
                        .add(0, 0, Short.MAX_VALUE))
                    .add(jScrollPane3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 360, Short.MAX_VALUE))
                .addContainerGap())
            .add(org.jdesktop.layout.GroupLayout.TRAILING, panPostAnncLayout.createSequentialGroup()
                .add(0, 0, Short.MAX_VALUE)
                .add(btnPostAnnc))
        );
        panPostAnncLayout.setVerticalGroup(
            panPostAnncLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(panPostAnncLayout.createSequentialGroup()
                .addContainerGap()
                .add(lblPostAnnc)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 73, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 14, Short.MAX_VALUE)
                .add(btnPostAnnc)
                .addContainerGap())
        );

        getContentPane().add(panPostAnnc, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 520, -1, 150));

        panViewSchedules.setBackground(new java.awt.Color(102, 102, 102));

        lblViewSched.setText("View Availability Schedules");

        lblGradAsst.setText("Graduate Asst:");

        cmbGradAsst.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cmbGradAsst.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbGradAsstActionPerformed(evt);
            }
        });

        tblViewAvail.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"08:00 AM", null, null, null, null, null},
                {"09:00 AM", null, null, null, null, null},
                {"10:00 AM", null, null, null, null, null},
                {"11:00 AM", null, null, null, null, null},
                {"12:00 PM", null, null, null, null, null},
                {"01:00 PM", null, null, null, null, null},
                {"02:00 PM", null, null, null, null, null},
                {"03:00 PM", null, null, null, null, null},
                {"04:00 PM", null, null, null, null, null}
            },
            new String [] {
                "", "M", "Tu", "W", "Th", "F"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.Boolean.class, java.lang.Boolean.class, java.lang.Boolean.class, java.lang.Boolean.class, java.lang.Boolean.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane9.setViewportView(tblViewAvail);

        btnGoSched.setText("Go");
        btnGoSched.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGoSchedActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout panViewSchedulesLayout = new org.jdesktop.layout.GroupLayout(panViewSchedules);
        panViewSchedules.setLayout(panViewSchedulesLayout);
        panViewSchedulesLayout.setHorizontalGroup(
            panViewSchedulesLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(panViewSchedulesLayout.createSequentialGroup()
                .add(25, 25, 25)
                .add(panViewSchedulesLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(lblViewSched)
                    .add(panViewSchedulesLayout.createSequentialGroup()
                        .add(lblGradAsst, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 103, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(cmbGradAsst, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 151, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(btnGoSched, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 50, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jScrollPane9, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 307, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(9, Short.MAX_VALUE))
        );
        panViewSchedulesLayout.setVerticalGroup(
            panViewSchedulesLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(panViewSchedulesLayout.createSequentialGroup()
                .addContainerGap()
                .add(lblViewSched)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(panViewSchedulesLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(lblGradAsst)
                    .add(cmbGradAsst, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(btnGoSched))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jScrollPane9, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 165, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(16, Short.MAX_VALUE))
        );

        getContentPane().add(panViewSchedules, new org.netbeans.lib.awtextra.AbsoluteConstraints(710, 10, 350, 250));

        panEditRoles.setBackground(new java.awt.Color(102, 102, 102));

        lblEditRoles.setText("Edit User Roles");

        lblStudents.setText("Students");

        lblGradAssts.setText("Grad Assistants");

        btnMakeGradAsst.setText("Make Grad Assistant");
        btnMakeGradAsst.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnMakeGradAsstActionPerformed(evt);
            }
        });

        btnMakeStudent.setText("Make Student");
        btnMakeStudent.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnMakeStudentActionPerformed(evt);
            }
        });

        tblStudents.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "First", "Last", "Username"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane1.setViewportView(tblStudents);

        tblGradAssts.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "First", "Last", "Username"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane11.setViewportView(tblGradAssts);

        org.jdesktop.layout.GroupLayout panEditRolesLayout = new org.jdesktop.layout.GroupLayout(panEditRoles);
        panEditRoles.setLayout(panEditRolesLayout);
        panEditRolesLayout.setHorizontalGroup(
            panEditRolesLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(panEditRolesLayout.createSequentialGroup()
                .add(panEditRolesLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(panEditRolesLayout.createSequentialGroup()
                        .addContainerGap()
                        .add(panEditRolesLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(lblGradAssts)
                            .add(lblEditRoles)
                            .add(lblStudents)))
                    .add(panEditRolesLayout.createSequentialGroup()
                        .add(48, 48, 48)
                        .add(btnMakeGradAsst, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 154, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(panEditRolesLayout.createSequentialGroup()
                        .addContainerGap()
                        .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 250, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(panEditRolesLayout.createSequentialGroup()
                        .addContainerGap()
                        .add(jScrollPane11, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 248, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(panEditRolesLayout.createSequentialGroup()
                        .add(73, 73, 73)
                        .add(btnMakeStudent)))
                .addContainerGap(44, Short.MAX_VALUE))
        );
        panEditRolesLayout.setVerticalGroup(
            panEditRolesLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(panEditRolesLayout.createSequentialGroup()
                .addContainerGap()
                .add(lblEditRoles)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(lblStudents)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 102, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(btnMakeGradAsst)
                .add(18, 18, 18)
                .add(lblGradAssts)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane11, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 109, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(btnMakeStudent)
                .addContainerGap(29, Short.MAX_VALUE))
        );

        getContentPane().add(panEditRoles, new org.netbeans.lib.awtextra.AbsoluteConstraints(710, 280, 300, 400));

        menuFile.setText("File");

        menuLogout.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_L, java.awt.event.InputEvent.CTRL_MASK));
        menuLogout.setText("Logout");
        menuLogout.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuLogoutActionPerformed(evt);
            }
        });
        menuFile.add(menuLogout);

        menuQuit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.CTRL_MASK));
        menuQuit.setText("Quit");
        menuQuit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuQuitActionPerformed(evt);
            }
        });
        menuFile.add(menuQuit);

        jMenuBar1.add(menuFile);

        menuHelp.setText("Help");

        menuAbout.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK));
        menuAbout.setText("About");
        menuAbout.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuAboutActionPerformed(evt);
            }
        });
        menuHelp.add(menuAbout);

        jMenuBar1.add(menuHelp);

        setJMenuBar(jMenuBar1);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnPostSubmitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPostSubmitActionPerformed
        
        String strQuestion = txtNewQ.getText();
        String strUsername = HelpDesk.accountName;
        int intVisibility = cmbVisibility.getSelectedIndex();
        int intCategory = cmbCategory.getSelectedIndex();
        
        //create string for VALUES sections of SQL statemenet
        String strValues = "VALUES('" + strQuestion + "', " + intVisibility + ", " + intCategory + ", '', '', '" + strUsername + "')";

        //try to insert username into tblUsers
        try
        {
            Statement s = HelpDesk.connection.createStatement ();
            s.executeUpdate("INSERT INTO tblQuestions (text, global, category, replyText, replyAuthor, author) " + strValues);
            s.close ();
        }
        catch (SQLException error)
        {
            System.err.println ("Error message: " + error.getMessage ());
            System.err.println ("Error number: " + error.getErrorCode ());
        }

        //tell user that account was successfully created
        JOptionPane.showMessageDialog(null, "Question posted successfully.");
        txtNewQ.setText("");
        updateForm();
    }//GEN-LAST:event_btnPostSubmitActionPerformed

    private void btnSubmitFormActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSubmitFormActionPerformed
        String strFilePath = txtForm.getText();
        submitForm = new File(strFilePath);
        // Try to upload the file to the FTP server
        if(submitForm != null && submitForm.exists())
        {
            
            String strUsername = HelpDesk.accountName;
            String strServerPath = strUsername + "/" + submitForm.getName();
        
            //create string for VALUES sections of SQL statemenet
            String strValues = "VALUES('" + strUsername + "', '" + strServerPath + "', " + 0 + ")";
            
            FTPClient client = new FTPClient();
            boolean success = true;
            
            try 
            {
                client.connect(HelpDesk.FTP_SERVER_ADDRESS, HelpDesk.FTP_PORT);
                int reply = client.getReplyCode();
                if(!FTPReply.isPositiveCompletion(reply))
                {
                    client.disconnect();
                    System.err.println("FTP Server refused the connection");
                    return;
                }
                
                // Start the file transfer
                client.login(HelpDesk.FTP_USERNAME, HelpDesk.FTP_PASSWORD);
                // Check to see if there is a directory, if not, make it and change to it
                if(!client.changeWorkingDirectory(strUsername))
                {
                    client.makeDirectory(strUsername);
                    client.changeWorkingDirectory(strUsername);
                }
                // Check for a file with the same name. If one exists, ask the
                // user if they want to overwrite it, or rename the current file.
                FTPFile[] list = client.listFiles();
                FTPFile f;
                boolean cancelled = false;
                for(int i = 0; i < list.length && !cancelled; ++i)
                {
                    f = list[i];
                    if(f.getName().equals(submitForm.getName()))
                    {
                        int retVal = JOptionPane.showConfirmDialog(this, "File with the same name exists. Overwrite?", "Name Conflict", 0);
                        if(retVal == 1)
                        {
                            cancelled = true;
                        }
                    }
                }
                if(!cancelled)
                {
                    //upload the file
                    InputStream in = new FileInputStream(submitForm);
                    client.setFileType(FTPClient.BINARY_FILE_TYPE);
                    success = client.storeFile(submitForm.getName(), in);
                }
                client.logout();
            } 
            catch (IOException ex) 
            {
                ex.printStackTrace();
                success = false;
            }
            finally
            {
                if(client.isConnected())
                {
                    try
                    {
                        client.disconnect();
                    }
                    catch (IOException e)
                    {
                        System.err.println("Problem disconnecting");
                    }
                }
            }
            
            if(success)
            {
                //try to insert form data into tblForms
                try
                {
                    Statement s = HelpDesk.connection.createStatement ();
                    s.executeUpdate("INSERT INTO tblForms (author, filePath, reviewed) " + strValues);
                    s.close ();
                    
                }
                catch (SQLException error)
                {
                    System.err.println ("Error message: " + error.getMessage ());
                    System.err.println ("Error number: " + error.getErrorCode ());
                    success  = false;
                }
                if(success)
                {
                    JOptionPane.showMessageDialog(null, "Form submitted successfully.");
                    txtForm.setText("");
                }
                else
                {
                    System.err.println("Error updating the entry in the database");
                }
            }
        }
        else
        {
            String message = "Please select a file either by browsing,\nor typing the file path.";
            JOptionPane.showMessageDialog(this, message, "No file selected", 0);
        }
        updateForm();
    }//GEN-LAST:event_btnSubmitFormActionPerformed

    private void btnQReplyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnQReplyActionPerformed
        String strUsername = HelpDesk.accountName;
        int intSelected = tblQuestions.getSelectedRow();
        int intUID = QuestionUID[intSelected];
        String strReply = JOptionPane.showInputDialog(null, "Enter your reply: ", "", 1);
        
        //try to insert reply into mysql table tblQuestions
        try
        {
            // setup and execute mysql update preparedstatement to add reply to a question
            String query = "update tblQuestions set replyText = ?, replyAuthor = ? where UID = ?";
            PreparedStatement pS = HelpDesk.connection.prepareStatement(query);
            pS.setString(1, strReply);
            pS.setString(2, strUsername);
            pS.setInt(3, intUID);
            pS.executeUpdate();
            pS.close();
        }
        catch (SQLException error)
        {
            System.err.println ("Error message: " + error.getMessage ());
            System.err.println ("Error number: " + error.getErrorCode ());
        }

        //tell user that form was successfully posted
        JOptionPane.showMessageDialog(null, "Reply submitted successfully.");
        updateForm();
    }//GEN-LAST:event_btnQReplyActionPerformed

    private void btnResetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnResetActionPerformed
        // set all boolean values to false in availability schedule
        for (int i = 0; i < 9; i++) {
            for (int j = 1; j < 6; j++) {
                tblAvail.setValueAt(false, i, j);
            }
        }
    }//GEN-LAST:event_btnResetActionPerformed

    private void btnReviewedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnReviewedActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btnReviewedActionPerformed

    private void cmbSortByVisActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbSortByVisActionPerformed
        // set global visibility variable to the selected index in the combo box
        intQuestionSort = cmbSortByVis.getSelectedIndex();
        updateForm();
        
    }//GEN-LAST:event_cmbSortByVisActionPerformed

    private void cmbGradAsstActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbGradAsstActionPerformed
        
       
    }//GEN-LAST:event_cmbGradAsstActionPerformed

    private void btnSubmitScheduleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSubmitScheduleActionPerformed
        try
        {
            Statement st = HelpDesk.connection.createStatement();
            String sql = "DELETE FROM tblSchedules WHERE username = '" + HelpDesk.accountName + "'";
            st.executeUpdate(sql);
            
            String query = "insert into tblSchedules value( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
            PreparedStatement pS = HelpDesk.connection.prepareStatement(query);
            pS.setString(1, HelpDesk.accountName);
            pS.setBoolean(2, ((Boolean) tblAvail.getValueAt(0,1)).booleanValue());
            pS.setBoolean(3, ((Boolean) tblAvail.getValueAt(0,2)).booleanValue());
            pS.setBoolean(4, ((Boolean) tblAvail.getValueAt(0,3)).booleanValue());
            pS.setBoolean(5, ((Boolean) tblAvail.getValueAt(0,4)).booleanValue());
            pS.setBoolean(6, ((Boolean) tblAvail.getValueAt(0,5)).booleanValue());
            pS.setBoolean(7, ((Boolean) tblAvail.getValueAt(1,1)).booleanValue());
            pS.setBoolean(8, ((Boolean) tblAvail.getValueAt(1,2)).booleanValue());
            pS.setBoolean(9, ((Boolean) tblAvail.getValueAt(1,3)).booleanValue());
            pS.setBoolean(10, ((Boolean) tblAvail.getValueAt(1,4)).booleanValue());
            pS.setBoolean(11, ((Boolean) tblAvail.getValueAt(1,5)).booleanValue());
            pS.setBoolean(12, ((Boolean) tblAvail.getValueAt(2,1)).booleanValue());
            pS.setBoolean(13, ((Boolean) tblAvail.getValueAt(2,2)).booleanValue());
            pS.setBoolean(14, ((Boolean) tblAvail.getValueAt(2,3)).booleanValue());
            pS.setBoolean(15, ((Boolean) tblAvail.getValueAt(2,4)).booleanValue());
            pS.setBoolean(16, ((Boolean) tblAvail.getValueAt(2,5)).booleanValue());
            pS.setBoolean(17, ((Boolean) tblAvail.getValueAt(3,1)).booleanValue());
            pS.setBoolean(18, ((Boolean) tblAvail.getValueAt(3,2)).booleanValue());
            pS.setBoolean(19, ((Boolean) tblAvail.getValueAt(3,3)).booleanValue());
            pS.setBoolean(20, ((Boolean) tblAvail.getValueAt(3,4)).booleanValue());
            pS.setBoolean(21, ((Boolean) tblAvail.getValueAt(3,5)).booleanValue());
            pS.setBoolean(22, ((Boolean) tblAvail.getValueAt(4,1)).booleanValue());
            pS.setBoolean(23, ((Boolean) tblAvail.getValueAt(4,2)).booleanValue());
            pS.setBoolean(24, ((Boolean) tblAvail.getValueAt(4,3)).booleanValue());
            pS.setBoolean(25, ((Boolean) tblAvail.getValueAt(4,4)).booleanValue());
            pS.setBoolean(26, ((Boolean) tblAvail.getValueAt(4,5)).booleanValue());
            pS.setBoolean(27, ((Boolean) tblAvail.getValueAt(5,1)).booleanValue());
            pS.setBoolean(28, ((Boolean) tblAvail.getValueAt(5,2)).booleanValue());
            pS.setBoolean(29, ((Boolean) tblAvail.getValueAt(5,3)).booleanValue());
            pS.setBoolean(30, ((Boolean) tblAvail.getValueAt(5,4)).booleanValue());
            pS.setBoolean(31, ((Boolean) tblAvail.getValueAt(5,5)).booleanValue());
            pS.setBoolean(32, ((Boolean) tblAvail.getValueAt(6,1)).booleanValue());
            pS.setBoolean(33, ((Boolean) tblAvail.getValueAt(6,2)).booleanValue());
            pS.setBoolean(34, ((Boolean) tblAvail.getValueAt(6,3)).booleanValue());
            pS.setBoolean(35, ((Boolean) tblAvail.getValueAt(6,4)).booleanValue());
            pS.setBoolean(36, ((Boolean) tblAvail.getValueAt(6,5)).booleanValue());
            pS.setBoolean(37, ((Boolean) tblAvail.getValueAt(7,1)).booleanValue());
            pS.setBoolean(38, ((Boolean) tblAvail.getValueAt(7,2)).booleanValue());
            pS.setBoolean(39, ((Boolean) tblAvail.getValueAt(7,3)).booleanValue());
            pS.setBoolean(40, ((Boolean) tblAvail.getValueAt(7,4)).booleanValue());
            pS.setBoolean(41, ((Boolean) tblAvail.getValueAt(7,5)).booleanValue());
            pS.setBoolean(42, ((Boolean) tblAvail.getValueAt(8,1)).booleanValue());
            pS.setBoolean(43, ((Boolean) tblAvail.getValueAt(8,2)).booleanValue());
            pS.setBoolean(44, ((Boolean) tblAvail.getValueAt(8,3)).booleanValue());
            pS.setBoolean(45, ((Boolean) tblAvail.getValueAt(8,4)).booleanValue());
            pS.setBoolean(46, ((Boolean) tblAvail.getValueAt(8,5)).booleanValue());
            pS.executeUpdate();
            pS.close();
        }
        catch (SQLException error)
        {
            System.err.println ("Error message: " + error.getMessage ());
            System.err.println ("Error number: " + error.getErrorCode ());
        }

        //tell user that form was successfully posted
        JOptionPane.showMessageDialog(null, "Availability schedule submitted successfully.");
    }//GEN-LAST:event_btnSubmitScheduleActionPerformed

    private void btnMakeGradAsstActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMakeGradAsstActionPerformed
        int index = tblStudents.getSelectedRow();
        String user = tblStudents.getValueAt(index, 2).toString();
        
        //try to update account status
        try
        {
            // setup and execute mysql update preparedstatement to add reply to a question
            String query = "update tblUsers set accountType = ? where username = ?";
            PreparedStatement pS = HelpDesk.connection.prepareStatement(query);
            pS.setInt(1, 1);
            pS.setString(2, user);
            pS.executeUpdate();
            pS.close();
        }
        catch (SQLException error)
        {
            System.err.println ("Error message: " + error.getMessage ());
            System.err.println ("Error number: " + error.getErrorCode ());
        }

        //tell user that form was successfully posted
        JOptionPane.showMessageDialog(null, "Update processed successfully.");
        updateForm();
    }//GEN-LAST:event_btnMakeGradAsstActionPerformed

    private void btnMakeStudentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMakeStudentActionPerformed
        int index = tblGradAssts.getSelectedRow();
        String user = tblGradAssts.getValueAt(index, 2).toString();
        
        //try to update account status
        try
        {
            // setup and execute mysql update preparedstatement to add reply to a question
            String query = "update tblUsers set accountType = ? where username = ?";
            PreparedStatement pS = HelpDesk.connection.prepareStatement(query);
            pS.setInt(1, 0);
            pS.setString(2, user);
            pS.executeUpdate();
            pS.close();
        }
        catch (SQLException error)
        {
            System.err.println ("Error message: " + error.getMessage ());
            System.err.println ("Error number: " + error.getErrorCode ());
        }

        //tell user that form was successfully posted
        JOptionPane.showMessageDialog(null, "Update processed successfully.");
        updateForm();
    }//GEN-LAST:event_btnMakeStudentActionPerformed

    private void menuLogoutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuLogoutActionPerformed
        LoginForm myLoginForm = new LoginForm();
        myLoginForm.setVisible(true);
        this.setVisible(false);
    }//GEN-LAST:event_menuLogoutActionPerformed

    private void menuQuitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuQuitActionPerformed
        System.exit(0);
    }//GEN-LAST:event_menuQuitActionPerformed

    private void menuAboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuAboutActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_menuAboutActionPerformed

    private void btnPostAnncActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPostAnncActionPerformed
        String strText = txtAnnc.getText();
        String strUsername = HelpDesk.accountName;
        
        //create string for VALUES sections of SQL statemenet
        String strValues = "VALUES('" + strUsername + "', '" + strText + "')";

        //try to insert form data into tblFormss
        try
        {
            Statement s = HelpDesk.connection.createStatement ();
            s.executeUpdate("INSERT INTO tblAnnouncements (author, text)" + strValues);
            s.close ();
        }
        catch (SQLException error)
        {
            System.err.println ("Error message: " + error.getMessage ());
            System.err.println ("Error number: " + error.getErrorCode ());
        }

        //tell user that form was successfully posted
        JOptionPane.showMessageDialog(null, "Announcement submitted successfully.");
        txtAnnc.setText("");
        updateForm();
    }//GEN-LAST:event_btnPostAnncActionPerformed

    private void btnBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBrowseActionPerformed
        JFileChooser chooser = new JFileChooser();
        chooser.setFileFilter((FileFilter)(new FormsFilter()));
        chooser.setMultiSelectionEnabled(false);
        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        int val = chooser.showOpenDialog(this);
        
        if(val == JFileChooser.APPROVE_OPTION)
            submitForm = chooser.getSelectedFile();
        else if(val == JFileChooser.CANCEL_OPTION)
            return;
        else if(val == JFileChooser.ERROR_OPTION)
            return;
        
        if(!submitForm.exists())
        {
            System.err.println("Selected form does not exist!");
        }
        else
        {
            try {
                txtForm.setText(submitForm.getCanonicalPath());
            } catch (IOException ex) {
                System.err.println("Error reading file");
            }
        }
    }//GEN-LAST:event_btnBrowseActionPerformed

    private void btnDownloadFormActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDownloadFormActionPerformed
        int row = tblForm.getSelectedRow();
        String path = (String)tblForm.getValueAt(row, 1);
        if(path == null)
            return;
        int i = path.lastIndexOf("/");
        String fileName, parent;
        if(i > 0)
        {
            fileName = path.substring(i+1);
            parent = path.substring(0, i);
        }
        else
        {
            fileName = path;
            parent = null;
        }
        
        File download = null;
        OutputStream os = null;
        FTPClient client = new FTPClient();
        
        try 
        {
            client.connect(HelpDesk.FTP_SERVER_ADDRESS, HelpDesk.FTP_PORT);
            if(!FTPReply.isPositiveCompletion(client.getReplyCode()))
            {
                System.err.println("FTP Server refused the connection");
                return;
            }
            client.login(HelpDesk.FTP_USERNAME, HelpDesk.FTP_PASSWORD);
            JFileChooser chooser = new JFileChooser();
            int status = chooser.showSaveDialog(this);
            if(status == JFileChooser.APPROVE_OPTION)
            {
                client.setFileType(FTPClient.BINARY_FILE_TYPE);
                download = chooser.getSelectedFile();
                os = new FileOutputStream(download);
                if((parent != null && client.changeWorkingDirectory(parent)) || (parent == null))
                {
                    client.retrieveFile(fileName, os);
                }
                os.close();
            }
            client.logout();
        } 
        catch (SocketException ex) 
        {
            System.err.println("Error communicating with the server. Are you allowing port 21 through your firewall?");
        } 
        catch (IOException ex) 
        {
            System.err.println("Error accessing the remote file/writing the local file.");
        }
        finally
        {
            if(os != null)
            {
                try 
                {
                    os.close();
                } 
                catch (IOException ex) 
                {
                    // Do nothing
                }
            }
            try 
            {
                client.disconnect();
            } 
            catch (IOException ex) 
            {
                // Do Nothing
            }
        }
        
    }//GEN-LAST:event_btnDownloadFormActionPerformed

    private void btnDeleteFormActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteFormActionPerformed
        int row = tblForm.getSelectedRow();
        String path = (String) tblForm.getValueAt(row, 1);
        if(path == null)
            return;
        
        int i = path.lastIndexOf("/");
        String fileName, parent;
        if(i > 0)
        {
            fileName = path.substring(i+1);
            parent = path.substring(0, i);
        }
        else
        {
            fileName = path;
            parent = null;
        }
        
        // Connect to the ftp server and check to see if it exists
        // If it does, remove it. If not, don't delete anything
        FTPClient client = new FTPClient();
        try 
        {
            client.connect(HelpDesk.FTP_SERVER_ADDRESS, HelpDesk.FTP_PORT);
            if(!FTPReply.isPositiveCompletion(client.getReplyCode()))
            {
                client.disconnect();
                System.err.println("Cannot establish a connection with the FTP server.");
                return;
            }
            
            client.login(HelpDesk.FTP_USERNAME, HelpDesk.FTP_PASSWORD);
            if(((parent != null) && client.changeWorkingDirectory(parent)) || (parent == null))
            {
                FTPFile[] list = client.listFiles();
                for(FTPFile f : list)
                {
                    if(f.getName().equals(fileName))
                    {
                        client.deleteFile(fileName);
                    }
                }
            }
            client.logout();
        }
        catch (SocketException ex) 
        {
            Logger.getLogger(StudentForm.class.getName()).log(Level.SEVERE, null, ex);
        } 
        catch (IOException ex) 
        {
            Logger.getLogger(StudentForm.class.getName()).log(Level.SEVERE, null, ex);
        }
        finally
        {
            try 
            {
                client.disconnect();
            } 
            catch (IOException ex) 
            {
                // It does nothing
            }
        }
        
        // Now, remove the entry from the SQL databse and update the form
        try
        {
            Statement s = HelpDesk.connection.createStatement ();
            String querySafeName = fileName.replaceAll("\\.", "\\\\.");
            String q = "DELETE FROM tblForms WHERE `filePath` REGEXP '"+querySafeName+"'";
            s.executeUpdate(q);
            s.close ();

        }
        catch (SQLException error)
        {
            System.err.println ("Error message: " + error.getMessage ());
            System.err.println ("Error number: " + error.getErrorCode ());
        }
        JOptionPane.showMessageDialog(this, "Object Successfully Removed from the server", "Successful Deletion", 1);
        updateForm();
    }//GEN-LAST:event_btnDeleteFormActionPerformed

    private void btnGoSchedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGoSchedActionPerformed
        //updateForm();
        
        schedIndex = cmbGradAsst.getSelectedIndex();
        System.out.println("item @ id1: " + schedIndex);
        System.out.println("username0: " + strGradAsstUsernames[0]);
        System.out.println("username1: " + strGradAsstUsernames[1]);
        System.out.println("username2: " + strGradAsstUsernames[2]);
        System.out.println("username3: " + strGradAsstUsernames[3]);
        System.out.println(schedIndex - 1);
           
        /**
        try
        {
            Statement sGo = HelpDesk.connection.createStatement();
            String myQuery1 = "SELECT 8M, 8Tu, 8W, 8Th, 8F, 9M, 9Tu, 9W, 9Th, 9F, 10M, 10Tu, 10W, 10Th, 10F, 11M, 11Tu, 11W, 11Th, 11F, 12M, 12Tu, 12W, 12Th, 12F, 1M, 1Tu, 1W, 1Th, 1F, 2M, 2Tu, 2W, 2Th, 2F, 3M, 3Tu, 3W, 3Th, 3F, 4M, 4Tu, 4W, 4Th, 4F FROM tblSchedules WHERE (username='"+ strGradAsstUsernames[schedIndex-1] +"')";
            sGo.executeQuery(myQuery1);
            ResultSet rsGo = sGo.getResultSet();
            System.out.println("prog1");
            //int count = 0;
            boolean booasdf = rsGo.getBoolean("8M");
            //tblViewAvail.setValueAt(rsGo.getBoolean("8M"),0,1);
            System.out.println("rsGo.getBoolean(8M)");
            tblViewAvail.setValueAt(rsGo.getBoolean("8Tu"),0,2);
            tblViewAvail.setValueAt(rsGo.getBoolean("8W"),0,3);
            tblViewAvail.setValueAt(rsGo.getBoolean("8Th"),0,4);
            tblViewAvail.setValueAt(rsGo.getBoolean("8F"),0,5);
            tblViewAvail.setValueAt(rsGo.getBoolean("9M"),1,1);
            tblViewAvail.setValueAt(rsGo.getBoolean("9Tu"),1,2);
            tblViewAvail.setValueAt(rsGo.getBoolean("9W"),1,3);
            tblViewAvail.setValueAt(rsGo.getBoolean("9Th"),1,4);
            tblViewAvail.setValueAt(rsGo.getBoolean("9F"),1,5);
            tblViewAvail.setValueAt(rsGo.getBoolean("10M"),2,1);
            tblViewAvail.setValueAt(rsGo.getBoolean("10Tu"),2,2);
            tblViewAvail.setValueAt(rsGo.getBoolean("10W"),2,3);
            tblViewAvail.setValueAt(rsGo.getBoolean("10Th"),2,4);
            tblViewAvail.setValueAt(rsGo.getBoolean("10F"),2,5);
            tblViewAvail.setValueAt(rsGo.getBoolean("11M"),3,1);
            tblViewAvail.setValueAt(rsGo.getBoolean("11Tu"),3,2);
            tblViewAvail.setValueAt(rsGo.getBoolean("11W"),3,3);
            tblViewAvail.setValueAt(rsGo.getBoolean("11Th"),3,4);
            tblViewAvail.setValueAt(rsGo.getBoolean("11F"),3,5);
            tblViewAvail.setValueAt(rsGo.getBoolean("12M"),4,1);
            tblViewAvail.setValueAt(rsGo.getBoolean("12Tu"),4,2);
            tblViewAvail.setValueAt(rsGo.getBoolean("12W"),4,3);
            tblViewAvail.setValueAt(rsGo.getBoolean("12Th"),4,4);
            tblViewAvail.setValueAt(rsGo.getBoolean("12F"),4,5);
            tblViewAvail.setValueAt(rsGo.getBoolean("1M"),5,1);
            tblViewAvail.setValueAt(rsGo.getBoolean("1Tu"),5,2);
            tblViewAvail.setValueAt(rsGo.getBoolean("1W"),5,3);
            tblViewAvail.setValueAt(rsGo.getBoolean("1Th"),5,4);
            tblViewAvail.setValueAt(rsGo.getBoolean("1F"),5,5);
            tblViewAvail.setValueAt(rsGo.getBoolean("2M"),6,1);
            tblViewAvail.setValueAt(rsGo.getBoolean("2Tu"),6,2);
            tblViewAvail.setValueAt(rsGo.getBoolean("2W"),6,3);
            tblViewAvail.setValueAt(rsGo.getBoolean("2Th"),6,4);
            tblViewAvail.setValueAt(rsGo.getBoolean("2F"),6,5);
            tblViewAvail.setValueAt(rsGo.getBoolean("3M"),7,1);
            tblViewAvail.setValueAt(rsGo.getBoolean("3Tu"),7,2);
            tblViewAvail.setValueAt(rsGo.getBoolean("3W"),7,3);
            tblViewAvail.setValueAt(rsGo.getBoolean("3Th"),7,4);
            tblViewAvail.setValueAt(rsGo.getBoolean("3F"),7,5);
            tblViewAvail.setValueAt(rsGo.getBoolean("4M"),8,1);
            tblViewAvail.setValueAt(rsGo.getBoolean("4Tu"),8,2);
            tblViewAvail.setValueAt(rsGo.getBoolean("4W"),8,3);
            tblViewAvail.setValueAt(rsGo.getBoolean("4Th"),8,4);
            tblViewAvail.setValueAt(rsGo.getBoolean("4F"),8,5);
            rsGo.close ();
            sGo.close ();
        }
        catch (SQLException error)
        {
            System.err.println ("Error message: " + error.getMessage ());
            System.err.println ("Error number: " + error.getErrorCode ());
        }
        * */
    }//GEN-LAST:event_btnGoSchedActionPerformed
    
    private class FormsFilter extends FileFilter {

        @Override
        public boolean accept(File f) {
            if(
               f.isDirectory() ||
               f.getName().endsWith(".pdf") ||
               f.getName().endsWith(".PDF") ||
               f.getName().endsWith(".doc") ||
               f.getName().endsWith(".DOC") ||
               f.getName().endsWith(".docx") ||
               f.getName().endsWith(".DOCX") ||
               f.getName().endsWith(".xls") ||
               f.getName().endsWith(".XLS") ||
               f.getName().endsWith(".xlsx") ||
               f.getName().endsWith(".XLSX") ||
               f.getName().endsWith(".ppt") ||
               f.getName().endsWith(".PPT") ||
               f.getName().endsWith(".pptx") ||
               f.getName().endsWith(".PPTX")
               )
                return true;
            else
                return false;
        }

        @Override
        public String getDescription() {
            return "Acceptable Forms (*.pdf, *.doc, *.docx, *.xls, *.xlsx, *.ppt, *.pptx)";
        }

    }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(StudentForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(StudentForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(StudentForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(StudentForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new StudentForm().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAnncReply;
    private javax.swing.JButton btnBrowse;
    private javax.swing.JButton btnDeleteForm;
    private javax.swing.JButton btnDownloadForm;
    private javax.swing.JButton btnGoSched;
    private javax.swing.JButton btnMakeGradAsst;
    private javax.swing.JButton btnMakeStudent;
    private javax.swing.JButton btnPostAnnc;
    private javax.swing.JButton btnPostSubmit;
    private javax.swing.JButton btnQReply;
    private javax.swing.JButton btnReset;
    private javax.swing.JButton btnReviewed;
    private javax.swing.JButton btnSubmitForm;
    private javax.swing.JButton btnSubmitSchedule;
    private javax.swing.JComboBox cmbCategory;
    private javax.swing.JComboBox cmbGradAsst;
    private javax.swing.JComboBox cmbSortByVis;
    private javax.swing.JComboBox cmbVisibility;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane11;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JScrollPane jScrollPane7;
    private javax.swing.JScrollPane jScrollPane8;
    private javax.swing.JScrollPane jScrollPane9;
    private javax.swing.JSeparator jSeparator9;
    private javax.swing.JLabel lblCategory;
    private javax.swing.JLabel lblEditRoles;
    private javax.swing.JLabel lblGradAsst;
    private javax.swing.JLabel lblGradAssts;
    private javax.swing.JLabel lblPostAnnc;
    private javax.swing.JLabel lblPostQ;
    private javax.swing.JLabel lblSetSched;
    private javax.swing.JLabel lblSortByVis;
    private javax.swing.JLabel lblStudents;
    private javax.swing.JLabel lblSubmitForm;
    private javax.swing.JLabel lblViewAnnc;
    private javax.swing.JLabel lblViewForms;
    private javax.swing.JLabel lblViewQs;
    private javax.swing.JLabel lblViewSched;
    private javax.swing.JLabel lblVisibility;
    private javax.swing.JMenuItem menuAbout;
    private javax.swing.JMenu menuFile;
    private javax.swing.JMenu menuHelp;
    private javax.swing.JMenuItem menuLogout;
    private javax.swing.JMenuItem menuQuit;
    private javax.swing.JPanel panEditRoles;
    private javax.swing.JPanel panPostAnnc;
    private javax.swing.JPanel panPostQ;
    private javax.swing.JPanel panSetSchedule;
    private javax.swing.JPanel panSubmitForm;
    private javax.swing.JPanel panViewAnnc;
    private javax.swing.JPanel panViewForms;
    private javax.swing.JPanel panViewQs;
    private javax.swing.JPanel panViewSchedules;
    private javax.swing.JTable tblAnnouncements;
    private javax.swing.JTable tblAvail;
    private javax.swing.JTable tblForm;
    private javax.swing.JTable tblGradAssts;
    private javax.swing.JTable tblQuestions;
    private javax.swing.JTable tblStudents;
    private javax.swing.JTable tblViewAvail;
    private javax.swing.JTextArea txtAnnc;
    private javax.swing.JTextField txtForm;
    private javax.swing.JTextArea txtNewQ;
    // End of variables declaration//GEN-END:variables
}
